User authentication is one of the most common tasks a
web programmer needs to perform. Any website with a login form
must implement some form of authentication.
This article describes how to develop a customized user
authentication module based on ASP.NET forms authentication. Along the way
you'll learn how to use the Macromedia custom DataSet tag in
Dreamweaver MX to access and use login credentials stored in a
database. First, you'll build a relatively simple
authentication system; then, you'll construct a more
comprehensive system.
In a typical scenario, you would want to limit access to
pages in a restricted directory to users who have logged in.
If a user requests a protected page before he or she logs in,
the page should redirect the user automatically to a login
page; likewise, when a user successfully logs in, the page
should redirect him/her to the the previously requested page,
within the restricted directory.
For example, a user who has not yet logged in (or a
logged-out user) attempts to access a page in the protected
members folder:
http://security/members/MemberOnlyFile.aspx
A page with forms authentication automatically redirects
the user to the login page in the root folder:
http://security/login.aspx?ReturnUrl=%2fmembers%2fMemberOnlyFile.aspx
Finally, the user logs in with the appropriate credentials
and the page automatically redirects him/her back to the
originally requested page.
For this article, I used Dreamweaver MX 6.1 to create
ASP.NET pages written in C#, and Microsoft IIS 5.0 to serve
the pages. The SQL Server 2000 database contains two tables,
called "members" and "manager":
|